/**
 * Copyright 2015-2016 eyaomall.cn
 * All rights reserved.
 *
 * @project
 * @author pro
 * @version 1.0
 * @date 2016-03-07
 */
package com.eyaomall.wxmanage.common.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.eyaomall.wxmanage.common.helper.MemberHelper;
import com.lycheeframework.core.common.helper.GlobEnv;

public class RedirectUtil {

	/**
	 * 直接跳转参数
	 * @return
	 */
	public static String redirect(String url){
		if(MemberHelper.getId() <= 0){
			try {
				url = URLEncoder.encode(GlobEnv.getWebURL(url), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				//...
			}
			
			return GlobEnv.getWebURL("login?redirectUrl=" + url);
		}
		
		return GlobEnv.getWebURL(url);
	}
	
	public static HttpServletRequest getRequest() {
		
		return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	}
}
